Micron Document




JavaScript syntax
part 43/59 · 107.4 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• There are differences between the various Web browsers with regard to which properties will be reflected with the for...in loop statement. In theory, this is controlled by an internal state property defined by the ECMAscript standard called "DontEnum", but in practice, each browser returns a slightly different set of properties during introspection. It is useful to test for a given property using if (some_object.hasOwnProperty(property_name)) { ... }. Thus, adding a method to the array prototype with Array.prototype.newMethod = function() {...} may cause for ... in loops to loop over the method's name.

While loop

The syntax of the JavaScript while loop is as follows:

while (condition) {
statement1;
statement2;
statement3;
...
}

Do ... while loop

The syntax of the JavaScript do ... while loop is as follows:

do {
statement1;
statement2;
statement3;
...
} while (condition);

With

The with statement adds all of the given object's properties and methods into the following block's scope, letting them be referenced as if they were local variables.

with (document) {
const a = getElementById('a');
const b = getElementById('b');
const c = getElementById('c');
};

• Note the absence of document. before each getElementById() invocation.

The semantics are similar to the with statement of Pascal.

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────